/**
 * 
 */
package com.demo2do.fms.entity.business.shipment;

import java.beans.Transient;
import java.math.BigDecimal;
import java.math.RoundingMode;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

/**
 * 运输成本 （目前用于生成派车单、回单确认、打印报销单）
 * 
 * @author Ysy
 *
 */
@Entity
@Table(name = "TBL_TRUCK_TRANSPORT_COST")
public class TransportCost {

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "generator")
    @SequenceGenerator(name = "generator", sequenceName = "HIBERNATE_SEQUENCE", allocationSize = 1)
    private Long id;
    
    /** 派车单ID */
    private Long dispatchOrderId;
    
    /** 路桥费 */
    private BigDecimal roadFee;
    
    /** 修理费 */
    private BigDecimal repairFee;
    
    /** 每公里修理费 */
    private BigDecimal repairFeePerKm;
    
    /** 轮胎费 */
    private BigDecimal tyreFee;
    
    /** 每公里轮胎费 */
    private BigDecimal tyreFeePerKm;
    
    /** 主驾重载工资单价 */
    private BigDecimal mainDriverFullSalary;
    
    /** 主驾空载工资单价 */
    private BigDecimal mainDriverEmptySalary;
    
    /** 主驾工资*/
    private BigDecimal mainDriverSalary;
    
    /** 第一副驾重载工资单价 */
    private BigDecimal firstViceDriverFullSalary;
    
    /** 第一副驾空载工资单价 */
    private BigDecimal firstViceDriverEmptySalary;
    
    /** 第一副驾工资*/
    private BigDecimal firstViceDriverSalary;
    
    /** 重载油耗*/
    private BigDecimal fullOilUsagePerKm;
    
    /** 空载油耗*/
    private BigDecimal emptyOilUsagePerKm;
    
    /** 重载公里数 */
    private BigDecimal fullLoadDistance;
    
    /** 空载公里数 */
    private BigDecimal emptyLoadDistance;
    
    /** 加油类型 */
    private Long oilTypeId;
    
    /** 加油量*/
    private BigDecimal oilUsage;
    
    /** 内部加油量*/
    private BigDecimal internalOilUsage;
    
    /** 内部加油变现量 */
    private BigDecimal internalOilUsageCompen;
    
    /** 内部油价*/
    private BigDecimal internalOilPrice;
    
    /** 内部加油地点 */
    private Long internalOilPlace;
    
    /** 外部油价*/
    @Column(name = "EXTERNALOIL_PRICE")
    private BigDecimal externalOilPrice;
    
    /** 内部油变现费 */
    private BigDecimal internalOilFeeCompensation;
    
    /** 外部油油费 */
    private BigDecimal externalOilFee;
    
    /** 油费总报销金额 */
    private BigDecimal totalOilFeeReimbursed;
    
    /** 其他费用审核人 */
    private String otherFeeAuditor;
    
    /**
     * the default constructor
     */
    public TransportCost() {
    }
    
    /**
     * @param internalOilPlace
     * @param internalOilUsage
     * @param internalOilUsageCompen
     * @param internalOilFeeCompensation
     * @param externalOilFee
     * @param totalOilFeeReimbursed
     * @return
     */
    public TransportCost editOilUsage(Long internalOilPlace, BigDecimal internalOilUsage, BigDecimal internalOilUsageCompen, BigDecimal internalOilFeeCompensation, BigDecimal externalOilFee, BigDecimal totalOilFeeReimbursed) {
        this.internalOilPlace = internalOilPlace;
        this.internalOilUsage = internalOilUsage;
        this.internalOilUsageCompen = internalOilUsageCompen;
        this.internalOilFeeCompensation = internalOilFeeCompensation;
        this.externalOilFee = externalOilFee;
        this.totalOilFeeReimbursed = totalOilFeeReimbursed;
        return this;
    }
    
    /**
     * @return
     */
    @Transient
    public BigDecimal getFullLoadRate() {
    	
    	BigDecimal loadDistance = fullLoadDistance.add(emptyLoadDistance);
    	if (BigDecimal.ZERO.equals(loadDistance)) {
    		return fullLoadDistance;
    	} else {
    		return fullLoadDistance.divide(loadDistance, 2, RoundingMode.HALF_UP);
    	}
    	
    }
    
    /**
     * @return
     */
    @Transient
    public BigDecimal getEmptyLoadRate() {
    	
    	BigDecimal loadDistance = fullLoadDistance.add(emptyLoadDistance);
    	if (BigDecimal.ZERO.equals(loadDistance)) {
    		return emptyLoadDistance;
    	} else {
    		return emptyLoadDistance.divide(loadDistance, 2, RoundingMode.HALF_UP);
    	}
    	
    }
    
    /**
     * 油费
     * 
     * @return
     */
    @Transient
    public BigDecimal getTotalOilFee() {
    	return externalOilFee.add(internalOilFeeCompensation);
    }
    
    /**
     * 内部加油量
     * 
     * @return
     */
    @Transient
    public BigDecimal getActualInternalOilUsage() {
    	return internalOilUsage.subtract(internalOilUsageCompen);
    }

    /**
     * @return the id
     */
    public Long getId() {
        return id;
    }

    /**
     * @return the dispatchOrderId
     */
    public Long getDispatchOrderId() {
        return dispatchOrderId;
    }

    /**
     * @return the roadFee
     */
    public BigDecimal getRoadFee() {
        return roadFee;
    }
    
    /**
     * @return the repairFee
     */
    public BigDecimal getRepairFee() {
        return repairFee;
    }
    
    /**
     * @return
     */
    public BigDecimal getRepairFeePerKm() {
        return repairFeePerKm;
    }
    
    /**
     * @return the tyreFee
     */
    public BigDecimal getTyreFee() {
        return tyreFee;
    }
    
    /**
     * @return
     */
    public BigDecimal getTyreFeePerKm() {
        return tyreFeePerKm;
    }

    /**
     * @return the mainDriverFullSalary
     */
    public BigDecimal getMainDriverFullSalary() {
        return mainDriverFullSalary;
    }

    /**
     * @return the mainDriverEmptySalary
     */
    public BigDecimal getMainDriverEmptySalary() {
        return mainDriverEmptySalary;
    }

    /**
     * @return the mainDriverSalary
     */
    public BigDecimal getMainDriverSalary() {
        return mainDriverSalary;
    }

    /**
     * @return the firstViceDriverFullSalary
     */
    public BigDecimal getFirstViceDriverFullSalary() {
        return firstViceDriverFullSalary;
    }

    /**
     * @return the firstViceDriverEmptySalary
     */
    public BigDecimal getFirstViceDriverEmptySalary() {
        return firstViceDriverEmptySalary;
    }

    /**
     * @return the firstViceDriverSalary
     */
    public BigDecimal getFirstViceDriverSalary() {
        return firstViceDriverSalary;
    }

    /**
     * @return the fullOilUsagePerKm
     */
    public BigDecimal getFullOilUsagePerKm() {
        return fullOilUsagePerKm;
    }
    
    /**
     * @return the fullLoadDistance
     */
    public BigDecimal getFullLoadDistance() {
        return fullLoadDistance;
    }

    /**
     * @return the emptyLoadDistance
     */
    public BigDecimal getEmptyLoadDistance() {
        return emptyLoadDistance;
    }

    /**
     * @return the emptyOilUsagePerKm
     */
    public BigDecimal getEmptyOilUsagePerKm() {
        return emptyOilUsagePerKm;
    }

    /**
     * @return the oilTypeId
     */
    public Long getOilTypeId() {
        return oilTypeId;
    }

    /**
     * @return the oilUsage
     */
    public BigDecimal getOilUsage() {
        return oilUsage;
    }

    /**
     * @return the internalOilUsage
     */
    public BigDecimal getInternalOilUsage() {
        return internalOilUsage;
    }
    
    /**
     * @return
     */
    public BigDecimal getInternalOilUsageCompen() {
        return internalOilUsageCompen;
    }

    /**
     * @return the internalOilPrice
     */
    public BigDecimal getInternalOilPrice() {
        return internalOilPrice;
    }
    
    /**
     * @return
     */
    public Long getInternalOilPlace() {
        return internalOilPlace;
    }

    /**
     * @return the externalOilPrice
     */
    public BigDecimal getExternalOilPrice() {
        return externalOilPrice;
    }
    
    /**
     * @return
     */
    public BigDecimal getInternalOilFeeCompensation() {
        return internalOilFeeCompensation;
    }
    
    /**
     * @return
     */
    public BigDecimal getExternalOilFee() {
        return externalOilFee;
    }

    /**
     * @return the totalOilFeeReimbursed
     */
    public BigDecimal getTotalOilFeeReimbursed() {
        return totalOilFeeReimbursed;
    }
    
    /**
     * @return the otherFeeAuditor
     */
    public String getOtherFeeAuditor() {
        return otherFeeAuditor;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @param dispatchOrderId the dispatchOrderId to set
     */
    public void setDispatchOrderId(Long dispatchOrderId) {
        this.dispatchOrderId = dispatchOrderId;
    }

    /**
     * @param roadFee the roadFee to set
     */
    public void setRoadFee(BigDecimal roadFee) {
        this.roadFee = roadFee;
    }
    
    /**
     * @param repairFee the repairFee to set
     */
    public void setRepairFee(BigDecimal repairFee) {
        this.repairFee = repairFee;
    }
    
    /**
     * @param repairFeePerKm
     */
    public void setRepairFeePerKm(BigDecimal repairFeePerKm) {
        this.repairFeePerKm = repairFeePerKm;
    }

    /**
     * @param tyreFee the tyreFee to set
     */
    public void setTyreFee(BigDecimal tyreFee) {
        this.tyreFee = tyreFee;
    }
    
    /**
     * @param tyreFeePerKm
     */
    public void setTyreFeePerKm(BigDecimal tyreFeePerKm) {
        this.tyreFeePerKm = tyreFeePerKm;
    }

    /**
     * @param mainDriverFullSalary the mainDriverFullSalary to set
     */
    public void setMainDriverFullSalary(BigDecimal mainDriverFullSalary) {
        this.mainDriverFullSalary = mainDriverFullSalary;
    }

    /**
     * @param mainDriverEmptySalary the mainDriverEmptySalary to set
     */
    public void setMainDriverEmptySalary(BigDecimal mainDriverEmptySalary) {
        this.mainDriverEmptySalary = mainDriverEmptySalary;
    }

    /**
     * @param mainDriverSalary the mainDriverSalary to set
     */
    public void setMainDriverSalary(BigDecimal mainDriverSalary) {
        this.mainDriverSalary = mainDriverSalary;
    }

    /**
     * @param firstViceDriverFullSalary the firstViceDriverFullSalary to set
     */
    public void setFirstViceDriverFullSalary(BigDecimal firstViceDriverFullSalary) {
        this.firstViceDriverFullSalary = firstViceDriverFullSalary;
    }

    /**
     * @param firstViceDriverEmptySalary the firstViceDriverEmptySalary to set
     */
    public void setFirstViceDriverEmptySalary(BigDecimal firstViceDriverEmptySalary) {
        this.firstViceDriverEmptySalary = firstViceDriverEmptySalary;
    }

    /**
     * @param firstViceDriverSalary the firstViceDriverSalary to set
     */
    public void setFirstViceDriverSalary(BigDecimal firstViceDriverSalary) {
        this.firstViceDriverSalary = firstViceDriverSalary;
    }

    /**
     * @param fullOilUsagePerKm the fullOilUsagePerKm to set
     */
    public void setFullOilUsagePerKm(BigDecimal fullOilUsagePerKm) {
        this.fullOilUsagePerKm = fullOilUsagePerKm;
    }
    
    /**
     * @param fullLoadDistance the fullLoadDistance to set
     */
    public void setFullLoadDistance(BigDecimal fullLoadDistance) {
        this.fullLoadDistance = fullLoadDistance;
    }

    /**
     * @param emptyLoadDistance the emptyLoadDistance to set
     */
    public void setEmptyLoadDistance(BigDecimal emptyLoadDistance) {
        this.emptyLoadDistance = emptyLoadDistance;
    }

    /**
     * @param emptyOilUsagePerKm the emptyOilUsagePerKm to set
     */
    public void setEmptyOilUsagePerKm(BigDecimal emptyOilUsagePerKm) {
        this.emptyOilUsagePerKm = emptyOilUsagePerKm;
    }

    /**
     * @param oilTypeId the oilTypeId to set
     */
    public void setOilTypeId(Long oilTypeId) {
        this.oilTypeId = oilTypeId;
    }

    /**
     * @param oilUsage the oilUsage to set
     */
    public void setOilUsage(BigDecimal oilUsage) {
        this.oilUsage = oilUsage;
    }

    /**
     * @param internalOilUsage the internalOilUsage to set
     */
    public void setInternalOilUsage(BigDecimal internalOilUsage) {
        this.internalOilUsage = internalOilUsage;
    }
    
    /**
     * @param internalOilUsageCompen
     */
    public void setInternalOilUsageCompen(BigDecimal internalOilUsageCompen) {
        this.internalOilUsageCompen = internalOilUsageCompen;
    }

    /**
     * @param internalOilPrice the internalOilPrice to set
     */
    public void setInternalOilPrice(BigDecimal internalOilPrice) {
        this.internalOilPrice = internalOilPrice;
    }
    
    /**
     * @param internalOilPlace
     */
    public void setInternalOilPlace(Long internalOilPlace) {
        this.internalOilPlace = internalOilPlace;
    }

    /**
     * @param externalOilPrice the externalOilPrice to set
     */
    public void setExternalOilPrice(BigDecimal externalOilPrice) {
        this.externalOilPrice = externalOilPrice;
    }
    
    /**
     * @param internalOilFeeCompensation
     */
    public void setInternalOilFeeCompensation(BigDecimal internalOilFeeCompensation) {
        this.internalOilFeeCompensation = internalOilFeeCompensation;
    }
    
    /**
     * @param externalOilFee
     */
    public void setExternalOilFee(BigDecimal externalOilFee) {
        this.externalOilFee = externalOilFee;
    }

    /**
     * @param totalOilFeeReimbursed the totalOilFeeReimbursed to set
     */
    public void setTotalOilFeeReimbursed(BigDecimal totalOilFeeReimbursed) {
        this.totalOilFeeReimbursed = totalOilFeeReimbursed;
    }
    
    /**
     * @param otherFeeAuditor the otherFeeAuditor to set
     */
    public void setOtherFeeAuditor(String otherFeeAuditor) {
        this.otherFeeAuditor = otherFeeAuditor;
    }
}
